package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Manager;
import service.ManagerService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/man")
public class MangerController {
    @Autowired
    private ManagerService managerService;
    @RequestMapping("/login")
    public String login(String name, String password, Model model, HttpServletRequest request){
        Manager manager = managerService.login(name, password);
        if(manager !=null){
            HttpSession session=request.getSession();
            session.setAttribute("manager",manager);
            return "main";
        }else {
            return "login";
        }

    }
    @RequestMapping("/tologin")
    public String tologin(){
        System.out.println("................");
        return "login";
    }
    @RequestMapping("/exit")
    public String exit(HttpSession session){
        session.removeAttribute("manager");
        return "login";
    }


}
